﻿#define _CRT_SECURE_NO_WARNINGS
#include"test.h"
void show_board(char board[ROW][COL], int row, int col)
{
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			printf(" %c ", board[i][j]);
			if (j < col - 1)
				printf("|");
		}printf("\n");
		if (i < row - 1)
		{
			for (int j = 0; j < col; j++)
			{
				printf("---");
				if (j < col - 1)
					printf("|");
			}printf("\n");
		}
	}
}
void init(char board[ROW][COL], int row, int col)
{
	for (int i = 0; i < row; i++)
		for (int j = 0; j < col; j++)
			board[i][j] = ' ';
}
void p_move(char board[ROW][COL], int row, int col)
{
	int x = 0;
	int y = 0;
	while (1)
	{
		printf("请输入坐标:>");
		scanf("%d %d", &x, &y);
		if (x > 0 && x <= row && y > 0 && y <= col)
		{
			if (board[x - 1][y - 1] == ' ')
			{
				board[x - 1][y - 1] = '*';
				break;
			}
			else
				printf("这里被占，请重新输入！\n");
		}
		else
			printf("输入错误，请重新输入！\n");
	}
}
void c_move(char board[ROW][COL], int row, int col)
{
	printf("电脑下：\n");
	while (1)
	{
		int x = rand() % row;
		int y = rand() % col;

		if (board[x][y] == ' ')
		{
			board[x][y] = '#';
			break;
		}

	}
}
int is_full(char board[ROW][COL], int row, int col)
{
	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			if (' ' == board[i][j])
				return 0;
		}
	}
	return 1;
}
void win(char board[ROW][COL], int row, int col)
{

	for (int i = 0; i < row; i++)
	{
		for (int j = 0; j < col; j++)
		{
			if (board[i][0] == board[i][1] && board[i][0] == board[i][2] && board[i][0] == '*')
				return '*';
			if (board[0][j] == board[1][j] && board[0][j] == board[2][j] && board[0][j] == '*')
				return '*';
			if (board[i][0] == board[i][1] && board[i][0] == board[i][2] && board[i][0] == '#')
				return '#';
			if (board[0][j] == board[1][j] && board[0][j] == board[2][j] && board[0][j] == '#')
				return '#';

		}
	}
	if (board[0][0] == board[1][1] && board[0][0] == board[2][2] && board[0][0] == '*')
		return '*';
	if (board[0][2] == board[1][1] && board[0][2] == board[2][0] && board[0][2] == '*')
		return '*';
	if (board[0][0] == board[1][1] && board[0][0] == board[2][2] && board[0][0] == '#')
		return '#';
	if (board[0][2] == board[1][1] && board[0][2] == board[2][0] && board[0][2] == '#')
		return '#';
	int ret = is_full(board, ROW, COL);
	if (1 == ret)
		return 'Q';
	return 'c';
}